import pymysql.cursors
import configparser
config = configparser.ConfigParser()
config.read('db.ini')
mysql_db=config['mysql']
host=mysql_db['host']
port=int(mysql_db['port'])
user=mysql_db['user']
password=mysql_db['password']
db=mysql_db['db']

connection = pymysql.connect(host=host,
                            port=port,
                            user=user,
                            password=password,
                            db=db,
                            charset='utf8mb4',
                            cursorclass=pymysql.cursors.DictCursor)

try:
    with connection.cursor() as cursor:
        # Create a new record
        sql = "insert into `py_users` (`email`, `password`) values (%s, %s)"
        cursor.execute(sql,('test@qq.com', '6666'))

        # connection is not autocommit by default , So you must commit to save your changes
    connection.commit()

    with connection.cursor() as cursor:
        # Read s single record
        sql = "select `id`, `password` from `py_users` where  `email`=%s"
        cursor.execute(sql, ('test@qq.com',))
        # result = cursor.fetchone()
        # results = cursor.fetchall()
        resultPage = cursor.fetchmany(2)
        print(resultPage)

finally:
    connection.close()